home *** CD-ROM | disk | FTP | other *** search
- Greetings!
-
- As we re-convene for this month, there are several things that need to be
- covered before we actually start the next lesson.
-
- The first one that I want to cover is to clear up a mistake in the LOCATE.BAS
- program in GWBT02. I must confess that I finished writing that program
- sometime around 2:00 am, and did not test it for errors as thoroughly as I
- should have, otherwise I would have quickly noted a very large error.
-
- As discussed in the message area, the use of the LOCATE statement is:
-
- LOCATE [row],[col]
-
- where [row] is a number between 1 and 25, and represents the screen line that
- you will print on; and [col] is a number between 1 and 80, and represents the
- screen column you will print on. Keeping this in mind, the LOCATE.BAS program
- should have looked like this:
-
- <please refer to enclosed file: LOCATE.BAS>
-
- Second, I am going to start doing something a little different in the archived
- version of the GWBT series - the archived version will separate the programs
- and text into different files, all contained within the archive file. The
- text file will continue to have the programs inserted inside of the file.
- Whichever one you wish to obtain, either the GWBTxx.TXT or GWBTxx.ZIP file,
- the contents will be the same except that where the text file will contain the
- program listing, the archived version will instead tell you which BASIC
- program goes there. This will save you from having to load a word processor
- and 'cut' all the program files out of the text, or having to re-type all of
- them in to try them out!
-
- Finally, the consensus seems to be that most everyone would prefer to have the
- live CONFERENCE session held on Friday or Saturday night, so this will be the
- night that we will be doing that. Watch the message area (IBMNEW, Message
- Area 10) for the announcement on the first on-line conference.
-
- ***************************************************************************
- Homework Assignment #1 - Designing an INPUT screen
- ***************************************************************************
-
- As you will remember, the first assignment was to take a pre-designed form (a
- check, in this case) and design a way for the user to enter check information
- for a business.
-
- You might be asking why we're going to so much trouble as to print a
- representation of the check on the screen and then jump around to fill in the
- blanks. Why not, instead, just write a simple routine that asks for each of
- the needed pieces of information as questions?
-
- The reason for the 'picture-and-fill-in-the-blanks' approach is that you may
- not know WHO will be running programs you write. It may be an experienced
- computer user, or someone who just turned one on for the first time!
-
- If it's the experienced user, they know what you're doing and will watch for
- cues from your program on what to do next, so we don't worry too much about
- them.
-
- But, if it's the beginner... They're usually scared out of their gourds that
- they're going to press that 'magic key' that makes everything on the computer
- go up in a cloud of smoke, or that they'll mess someone else's information up,
- or that the computer 'just won't like them'!
-
- So, for these users, we want to make them feel as much at home as we possibly
- can. Therefore, give them a blank check to look at, and they feel a little
- more at home. They've filled out hundreds of these little devils! The only
- difference now is that we want them to use a computer to fill in the blanks
- instead of a pen.
-
- The more 'at ease' you can make the user of your software feel, the more
- likely he/she is to use it properly and not be so worried.
-
- Before I present my solution to this problem, I want to stress AGAIN that
- your program will probably not look a lot like mine in many respects. This is
- not a real problem! As long as your program accomplishes the desired tasks
- set out in the flowchart, minor differences will not make your solution any
- worse than mine, only different.
-
- <please refer to enclosed file: CHECK.BAS>
-
- Let's examine the program one section at a time, so you can see what I was
- thinking about as I wrote it, relating it to the 'flowchart' of steps we made
- in the last lesson:
-
- LINES 10 through 90 are simply comments that document (for the programmer)
- what we're doing. The variables used are listed by name and type, so you can
- go back even years later and remember what you used each variable for.
-
- LINE 100 marks the start of the first actual part of the program, is a clear
- and concise reminder to you of what you're accomplishing here, in this case
- setting up the screen and printing the check.
-
- LINE 110 handles the first step of our flowchart: Clear the screen of anything
- already there.
-
- LINES 120 to 150 handle step two: Move to line 25, print a message that the
- user is entering a check, then return to line 1.
-
- LINES 160 to 280 handle step three: Print a reproduction of the check on the
- screen, one line at a time. This is probably where your program will start to
- look markedly different from mine!
-
- I prefer to use some sort of marker to show the user how much room they have
- to enter information. In this case, I used the underline (_) character to
- represent the number of spaces available in each area to enter information (in
- computereese, these are called 'input fields') so the user can see how much
- room they have.
-
- LINE 290 marks the start of the second phase of the program, getting the
- information from the user.
-
- Now, a little thought went into the next few steps. I wanted a way to show
- the user where he/she was on the screen now, accept the input, then move on to
- the next 'input field' and get more information. I used the following
- detailed flowchart to accomplish this:
-
- -----> Move the cursor to the next input field, then back two spaces
- | |
- | V
- | Use the INPUT command to get the information
- | |
- | V
- | Move back to the same INPUT point again
- | |
- | V
- | Print a single space to erase the question mark INPUT
- | command put on the screen
- | |
- | V
- <----------------<--------------------
-
- Since INPUT prints a question mark followed by a blank space to indicate that
- you are to supply some information, I simply added two blank spaces in front
- of each 'input field' to make room for them, and subtracted two from the
- actual start of the underlines. BASIC's INPUT statement then printed its
- question mark and blank space in the two spaces I allowed for them, and
- started accepting information on the first space of the underlines. Following
- the end of the INPUT statement, I moved back and 'erased' the question mark by
- printing a blank space over it. This has the effect of making it look like
- the question mark INPUT provides is moving from each 'input field' to the next
- one, and the operator can see where he/she is to put more information by
- looking for the question mark.
-
- Using this series of steps, the next five steps in the flowchart from GWBT02
- are as follows:
-
- LINES 300 to 330 accomplish step four: Move the cursor to the check number
- area and accept the check number.
-
- LINES 340 to 370 accomplish step five: Move the cursor to the check date area
- and accept the check date.
-
- LINES 380 to 410 accomplish step six: Move the cursor to the payor line and
- accept the payor's name.
-
- LINES 420 to 450 accomplish step seven: Move the cursor to the amount line
- and accept the amount of the check.
-
- LINES 460 to 490 accomplish step eight: Move the cursor to the memo line and
- accept the check memorandum (information).
-
- LINE 500 is the BASIC 'END' command that tells BASIC we're done with our
- program, and LINE 510 is our remark line that tells us we're finished as well.
-
- As I stated previously, THIS IS ONLY ONE WAY that the necessary steps can be
- carried out! If yours is different, the only thing you really need to be
- concerned about is that it accomplishes the job properly!
-
- (A SHORT SIDELINE ON ETHICS OF PROGRAMMING:)
-
- It never hurts to look at how others solve programming problems. Everyone
- looks at a problem a little bit differently, and someone else's approach might
- appeal to you more than your own. However, you want to use caution in
- 'borrowing' parts of other people's programs. Rich Little once quoted that
- "Imitation is the sincerest form of flattery"; but in the computer world the
- saying should probably be more like, "Imitation is the basis for litigation"!
-
- The materials presented in these GWBT files are placed in the 'public domain'
- by my own actions. That is, I freely allow others to use them, as long as I
- am given credit (see the new section at the end, the DISCLAIMER), and many
- others do similarly release some of their work into the 'public domain' as
- well.
-
- However, COPYRIGHTED materials are a different matter. Depending on the mood
- of the judge in the week in question, copyright by the author can extend all
- the way from the actual way the program was written to the way it 'looks and
- feels', how it operates and appears on the screen! 'Borrowing' ideas from
- copyrighted material is not wise, as the copyright holder then may have legal
- basis to sue you!
-
- My utilities (RLEPRT, an RLE graphic display program; and TTIME, a file
- transfer time estimation utility) are copyrighted material, and I assure you
- that I would NOT be very happy to see my months of work copied by someone else
- in disregard of my copyright. I can also assure you that any other author of
- software would respond in the same manner!
-
- Some authors do give out copies of their 'source code' (computereese for the
- program that does the work) as part of a package. It is made quite clear that
- you are allowed only limited rights to use this 'source code' for your own
- personal use, and that this does NOT include packaging parts of it in your own
- software.
-
- I would suggest that as you look at others programs, and see parts of them
- that you like, you should contact the author BEFORE using any part of his
- programs within your own! This is the best way to avoid future problems.
-
- Enough preaching for now! Let's dig into this month's tutorial topic:
-
- *************************************************************************
- GW-BASIC TUTORIAL PART THREE: Using disk and printer from BASIC
- *************************************************************************
-
- So far, all our BASIC efforts have been centered around using the keyboard and
- screen for all input and output. This is fine for programs that are run, then
- the information that is either given to the program or generated by the
- program are never needed again. Suppose we want to keep some record of what
- we've done, either in printed form, or in a form that we can use again?
-
- It is possible, however, to use other devices that are connected to your
- computer (that is, the disk and printer) to make such permanent copies of our
- information.
-
- As an illustration, think for a moment about the old-time switchboard
- operators, circa 1930. If you had an incomming call, the operator would
- connect it to your telephone by plugging a cable into a jack labeled with your
- name or phone number, and if you wanted to make an outgoing call, the operator
- would plug into your jack one of the outgoing lines.
-
- Now, imagine that our operator has six lines available to use, but three of
- them are reserved. One is marked for normal incomming calls, one is marked
- for normal outgoing calls, and one is marked for emergency calls only.
-
- This leaves the operator three lines that can be connected as necessary.
- These lines can used to communicate with any telephone connected to the
- operator's switchboard, and depending on the type of phone, can be for
- incomming calls only, outgoing calls only, or for both incomming and outgoing
- calls.
-
- BASIC's input and output function much the same as this illustration. BASIC
- normally reserves six input/output 'handles' for itself, and assigns three of
- them for special functions. The first is the 'standard input' (normally your
- keyboard), the second is the 'standard output' (normally your monitor), and
- the third is the 'error output' (always your monitor). This leaves you three
- channels (referred to in computereese as 'handles') for you to use.
-
- To assign one of the three available 'handles' to another input or output
- device, you need to tell BASIC which device you'll be using, and in what mode
- you'll be using it. Each device that BASIC can communicate with has a name
- that describes it to both BASIC and the user.
-
- Please don't become confused about the word 'device'. I (and BASIC) use the
- word device to refer to any physical item (parallel printers, disk files,
- modems, serial port printers, and so on) that BASIC can communicate with or
- exchange information to or from. Just think that in any place in the
- following section that you see the word 'device', you can replace it with the
- desired input/output device, such as replacing device with 'printer', 'modem',
- 'serial port', 'disk file' and so on.
-
- BASIC understands the following devices and can use them as listed:
-
- Device Name What device is and how you can use it:
-
- KYBD: Keyboard (Input only)
- SCRN: Screen (Output only)
- LPT1: Parallel Printer Port #1 (Output only)
- LPT2: Parallel Printer Port #2 (Output only)
- LPT3: Parallel Printer Port #3 (Output only)
- COM1: Serial Port #1 (Input or Output)
- COM2: Serial Port #2 (Input or Output)
- [filename] Disk file (Input or Output)
-
- Note that with the exception of the last device ([filename]), all device names
- have four letters and have a colon (:) at the end of their name.
-
- The use of [filename] as a device is a special case. In this case, the
- [filename] is any allowable DOS file name, and may need to include information
- on what drive or directory the file is in.
-
- The way you tell BASIC you want to use an alternate input/output device is
- with the OPEN command:
-
- OPEN "[device]" FOR [access] AS #[number]
-
- where:
-
- [device] is either one of the device names listed above, or a valid
- DOS filename (detailed below)
-
- [access] is either INPUT or OUTPUT (we will cover other modes later
- but for now these two will do what we need)
-
- [number] is a number from 1 to 3
-
- Let's look at some examples of opening input and output:
-
- To use a file called PROGRAM.LST in the PROGRAM subdirectory of the C: drive,
- and use this file for input as your first device:
-
- OPEN "C:\PROGRAM\PROGRAM.LST" FOR INPUT AS #1
-
- To open your printer (attached to the first port) for printing as the second
- device:
-
- OPEN "LPT1:" FOR OUTPUT AS #2
-
- You can only use each available 'handle' (device number) once. For example,
- you cannot open a file for input and a printer as:
-
- OPEN "C:\PROGRAM\PROGRAM.LST" FOR INPUT AS #1
- OPEN "LPT1:" FOR OUTPUT AS #1
-
- because BASIC would then become confused as to which #1 you meant - was it the
- printer, or the disk file? Each printer, file, serial port, and so on that
- you give a 'handle' (number) to must have a different number, between 1 and 3.
-
- If you wish to re-use a 'handle' for another device, you must first close it.
- BASIC does this by using the CLOSE command:
-
- CLOSE #[number]
-
- where [number] is the 'handle' to close.
-
- Once you have opened a device, you then use modified forms of the INPUT and
- PRINT statements to either input (get information from the device to BASIC) or
- output (send information from BASIC to the device) as shown below:
-
- INPUT #[number],[variable]
-
- where [number] is the device number, and [variable] is the information that
- you want to read in from that device; and
-
- PRINT #[number],[variable]
-
- - or -
-
- PRINT #[number],"[string to be printed]"
-
- where [number] is the device number, and either [variable] is the variable to
- print, or [string to be printed] is the information you want to print to that
- device.
-
- Let's look at a sample program to show how we can use these alternate input
- and output devices:
-
- <please refer to enclosed file: INANDOUT.BAS>
-
- To make this program work, I needed to sneak in a few things we haven't
- covered yet, so let me briefly explain them:
-
- In lines 280 and 390, you see: IF LINEOFDATA$="" THEN GOTO (line number).
- This is simply a test where if the variable LINEOFDATA$ is empty (for string
- variables, an empty variable is represented by the two quote characters next
- to each other ("") with nothing between. If the variable LINEOFDATA$ is
- indeed empty, then the GOTO command is executed. If LINEOFDATA$ is NOT empty,
- then BASIC continues with the next program line as numbered.
-
- The GOTO command used in the above lines, and also in lines 300 and 410 are
- simply commands that tell BASIC to disregard the normal rule to start at the
- lowest numbered line and keep running each line, in order, until the END. A
- GOTO tells BASIC to go to the line number listed after the word GOTO.
-
- In summary, the basic points to remember about opening devices for BASIC to
- read from or write to are as follows:
-
- 1) The device must either be a disk file, or one of the devices listed in the
- list of devices at the beginning of this section of the tutorial
-
- 2) Each device, when opened, must have a unique number (either 1, 2 or 3)
- assigned to it to identify it to both you and BASIC
-
- 3) Once opened, you use modified versions of INPUT/LINE INPUT and PRINT to
- either read from the device (this is INPUT or LINE INPUT) or to send
- information to the device (this is either PRINT or PRINT USING)
-
- 4) When finished with a device, you should CLOSE the device so that you can
- either re-use the device number ('handle') or to be sure that all information
- written to the file is written out.
-
- ***************************************************************************
- HOMEWORK ASSIGNMENT #2 - Using DISK files to save information
- ***************************************************************************
-
- You have delivered your check 'input screen' to the customer, and he is
- extremely happy with it! He has now requested that you see if there is a
- way to save information entered on each check to disk.
-
- This is the list of information that he wants saved to disk:
-
- Check Number Six characters
- Check Date Ten characters (00/00/0000)
- Paid To Fifty characters
- Amount Ten characters (0000000.00)
- Memo Forty characters
-
- This information should be saved to a disk file called CHECKS.DAT, and should
- be saved in a format that can be easily read as needed.
-
- Since BASIC (and DOS) work best with files where all records (each check we
- enter will be a 1-line 'record') are multiples of 2, let's add eleven blank
- spaces to the end of the check data. Remember also that BASIC will add a
- carriage return (ENTER) to the end of each line, so our layout for the
- CHECKS.DAT file looks like this:
-
- Check Number Six characters (000000)
- Check Date Ten spaces, character-based
- Paid To Fifty spaces, character-based
- Amount Ten characters (0000000.00)
- Memo Forty spaces, character-based
- Filler Eleven characters, blank
- Carriage Return One character, supplied by BASIC
-
- The total length of each 'check record' is now 128 characters, and this will
- allow BASIC and DOS to use the disk space in the most efficient, fastest
- manner possible.
-
- The customer also wants to be able to press the ENTER key, without entering a
- check number, to show that there are no more checks to enter. This would have
- the effect of making the check number equal to zero.
-
- Here's a flowchart of what we need to accomplish this job:
-
-
- ---------->------- Ask user for check number
- | |
- | |
- | Is check number equal to zero?
- | |
- | | YES
- | |-----------------------------
- ^ N| |
- | O| Close Disk Files
- | | and END
- ^ Ask user for check data
- | |
- | Ask user for Payor
- | |
- ^ Ask user for amount of check
- | |
- | Ask user for memorandum
- | |
- | Print information to disk
- | |
- -<----------<------------------
-
- I want you to construct a PRINT USING template that will print the information
- to disk in the order listed above, so your template will need to contain the
- following 'fields' of the listed lengths, in this order:
-
- 6 numeric, 10 alphabetic, 50 alphabetic, 10 numeric (seven numbers, decimal
- point, 2 numbers), 40 alphabetic, 12 alphabetic.
-
- Review the 'PRINT USING' information for how to set this up. If you cannot
- figure it out, ask for help in the IBMNEW/Basic Workshop message area for
- help. I would like you to try it on your own first.
-
- You should be able to re-use all of your earlier homework assignment from
- GWBT02, with these additions:
-
- 1) Add the test to see if the check number is zero. If it is, use a GOTO to
- take the program to the end where you will CLOSE your disk file and END
-
- 2) Add the lines necessary to use PRINT USING to print the check information
- to disk, then a GOTO to go back and get another check entry from the user.
-
- 3) If you want to add (a) line(s) to a BASIC program, all you need to do is
- to see where you want to add it, then use a number between the two lines for
- the insertion. For example, if you want to insert a line after 140 and before
- 150, just type it in, using line number 145. LIST your program, and behold!
- It's there and in the right order. If you want to add more than one, use a
- smaller number (in the example, we could add lines 141,142,143,...,147,148,149
- adding nine lines in all).
-
- This is where life begins to get a little harder! Remember, if you have any
- questions, or get absolutely stumped, just GO IBMNEW and enter Message Area
- #10 (BASIC Workshop) and we'll get you pointed in the right direction!
-
- Good Luck and Good Programming!
- <end of file>
-
-